//
//  HYFEmoticonPageView.swift
//  MyWeibo
//
//  Created by 黄勇锋 on 16/7/29.
//  Copyright © 2016年 黄勇锋. All rights reserved.
//

import UIKit

private let emoticonPageViewCellId = "emoticonPageViewCellId"


class HYFEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        backgroundColor = RandomColor()
        dataSource = self
        delegate = self
        
        registerClass(HYFEmoticonPageViewCell.self, forCellWithReuseIdentifier: emoticonPageViewCellId)
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .Horizontal
        
    }
}


extension HYFEmoticonPageView:UICollectionViewDataSource,UICollectionViewDelegate{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return HYFEmoticonTools.sharedTools.allEmoticons.count
    }

    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return HYFEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(emoticonPageViewCellId, forIndexPath: indexPath) as! HYFEmoticonPageViewCell
        
        cell.emoticons = HYFEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        cell.backgroundColor = self.backgroundColor
        
        return cell  
    }
}






